/**
 * 
 * @returns json对象parse原理
 */
    function parse(){
        //let javaData = '{"errcode":0,"errmsg":"ok"}'
    //1 去点【‘{} 空格】 => 'errcode:0,errmsg:ok'
    let str = javaData.replace(/''|{|}}\s/g,'')
    //2 按照【，】分割 => ['errcode:0,errmsg:ok']
    let arr = str.split(',')
    //4 遍历上面:定义空对象
    let obj = {}
    //3 遍历 item='errcode:0'
    arr.forEach(item =>{
        //5 遍历里面：按照【：】分割
        let temp = item.split(':') //['errcode',0]
         //6 遍历里面：数组的第一个值就是键，数组的第二个值就是值
    // ojb.键 = 值
    // obj.[temp[0]] = temp[1]
        obj[temp[0]] = isNaNif (isNaN(Number(temp[1]))) ? temp[1] : Number(temp[1])
    })
    //console.log(obj);
    return obj
    }


/**
 * 
 * @param {*} obj 
 * @returns json对象stringify原理
 */    
function stringify(obj)
{
    //let obj = {"errcode":0."errmsg":"ok","status":true}
    // 1 定义空数组
    let arr = []
    // 2 遍历对象 将【键 值】push到数组中
    for (let key in obj)
    {
        //console.log(key,obj[key]);
        let val = obj[key]
        if (!['boolean','number'].includes(typeof val))
        {
            val = `"${obj[key]}`
        }
        arr.push(`"${key}":${val}`)
    }
    // 3 拼接程json数据格式
    //console.log(`{${arr.join(',')}}`);
    return(`{${arr.join(',')}}`);

}
    
